package com.mes_for_xxxxxx.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mes_for_xxxxxx.entity.Workshop;
import com.mes_for_xxxxxx.entity.common.PageInfo;
import com.mes_for_xxxxxx.entity.common.Result;
import com.mes_for_xxxxxx.service.IWorkshopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * <p>
 * 车间信息表，存储车间相关信息 前端控制器
 * </p>
 *
 * @author 179005
 * @since 2024-09-10
 */
@RestController
@RequestMapping("/workshop")
public class WorkshopController {
    @Autowired
    private IWorkshopService workshopService;

    @PostMapping("/page")
    public Result pageWorkshop(PageInfo pageInfo){
        Page<Workshop> page = new Page<>(pageInfo.getPageNum(),pageInfo.getPageSize());
        return Result.success(workshopService.page(page));
    }

    @PostMapping("/add")
    public Result addWorkshop(Workshop workshop){
        workshop.setIsActive(true);
        workshop.setCreateTime(LocalDateTime.now());
        workshop.setUpdateTime(LocalDateTime.now());
        return Result.success(workshopService.save(workshop));
    }

    /**
     * 根据工艺路线id和工序id获取车间信息
     * @param route_id
     * @param flow
     * @return
     */
    @GetMapping("/getFlow/{route_id}/{flow}")
    public Result getWorkShopByFlow(@PathVariable String route_id,@PathVariable String flow){
        return Result.success(workshopService.getWorkShopByFlow(route_id,flow));
    }
}
